#include "player.h"

#include <iostream>

polaris::player::player()
{
    posX = 0;
    posY = 0;
    posZ = 0;


    viewposX = 0;
    viewposY = 0;
    viewposZ = 0;

    w = 0;
    h = 0;

    score = 0;

    lives = 0;

    forceX = 0;
    forceY = 0;
}

polaris::player::player(char *filename)
{
    posX = 0;
    posY = 0;
    posZ = 0;

    viewposX = 0;
    viewposY = 0;
    viewposZ = 0;

    w = 0;
    h = 0;

    score = 0;

    lives = 0;

    forceX = 0;
    forceY = 0;

    loadimg(filename);
 
}


bool polaris::player::loadimg(char* filename)
{
    if(gfx = SDL_LoadBMP(filename))
    {
            w = gfx->w;
            h = gfx->h;

            Uint32 colorkey = SDL_MapRGB(gfx->format, 0, 0, 255);
            SDL_SetColorKey( gfx, SDL_SRCCOLORKEY| SDL_RLEACCEL, colorkey );

            return true;
    }
    else return false;
}




void polaris::player::loadframe(char* filename)
{
	SDL_Surface *toload;
	if(toload = SDL_LoadBMP(filename))
	{
		Uint32 colorkey = SDL_MapRGB(toload->format, 0, 0, 255);
        	SDL_SetColorKey( toload, SDL_SRCCOLORKEY| SDL_RLEACCEL, colorkey );

		anim.push_back(toload);
	}
	else 
	{
		std::cout << "File not found. " << filename << std::endl;
		exit(-1);
	}
}

bool polaris::player::colli(polaris::player *other)
{
        if(other->posX+other->w > this->posX
	&& other->posX < this->posX
        && other->posY    <   this->posY+this->h
        && other->posY+ other->h    >  this->posY) return true;

        return false;
}

